﻿#ifndef _SHELL_BYTE_BUF_H_
#define _SHELL_BYTE_BUF_H_

typedef char int8;
typedef short int16;
typedef int int32;
typedef long long int64;

class ByteBuf
{
  public:
    ByteBuf();
    virtual ~ByteBuf();
    //byte
    int8 readInt8();
    void writeInt8(int8 value);
    // short
    int16 readInt16();
    void writeInt16(int16 value);
    // int
    int32 readInt32();
    void writeInt32(int32 value);
    void writeInt32(int32 value, int pos);
    // long
    int64 readInt64();
    void writeInt64(int64 value);
    //byte*
    void* readDatas(int len);
    void writeDatas(const void* const datas, int len);

    int32 readableSize();

    void resetRead();
    void resetWrite();
    void reset();

    void* getBuf();

  private:
    char* buf;
    int size;
    int read_pos;
    int write_pos;

    void check_write_resize(int len);
    void check_write_resize(int len, int pos);
};

#endif

